package hall

import (
	"context"
	hallManager "webgame/internal/manager/hall"
	"webgame/internal/model/entity/hall"
	"webgame/pb"

	"github.com/topfreegames/pitaya/v2"
	"github.com/topfreegames/pitaya/v2/component"
	"github.com/topfreegames/pitaya/v2/logger"
)

type LoginHandler struct {
	component.Base
}

func NewLoginHandler() *LoginHandler {
	return &LoginHandler{}
}

func (p *LoginHandler) Login(ctx context.Context, reqLogin *pb.CSLogin) (*pb.SCLoginRet, error) {
	s := pitaya.GetSessionFromCtx(ctx)
	info := &hall.LoginInfo{
		SessionId: s.UID(),
		Account:   *reqLogin.Account,
		Password:  *reqLogin.Token,
		LoginType: *reqLogin.LoginType,
	}

	err := hallManager.LoginManager.StartDoLogin(info)

	if err != nil {
		logger.Log.Errorf("[LoginHandler] doStartLogin failed,error=%s", err.Error())
		return nil, err
	}

	return nil, err
}
